#include<bits/stdc++.h>
using namespace std;

#define int long long

int t, n, res, v[2144], dp[2144][2144], f[2144][2144];

signed main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> t;
    while(t--){
        cin >> n, res = 0;
        for(int i = 1; i <= n; i++)
            cin >> v[i];
        for(int i = 0; i <= n; i++)
            for(int j = 0; j <= n; j++)
                dp[i][j] = f[i][j] = 0;
        for(int i = 0; i <= n; i++){
            int cnt = 0;
            for(int j = 0; j < i - 1; j++){
                dp[i][j] = dp[i - 1][j] + (v[i] == v[i - 1] ? v[i] : 0);
                if(j)
                    cnt = max(cnt, dp[i - 1][j] + (v[i] == v[j] ? v[i] : 0));
            }
            dp[i][i - 1] = cnt;
        }
        for(int i = 0; i < n; i++)
            res = max(res, dp[n][i]);
        cout << res << endl;
    }
    return 0;
}